#include <assert.h>
#include <irrlicht.h>
#include "demo.h"
#include "fx_lampskutta.h"


using namespace irr;
using namespace irr::core;
using namespace irr::scene;


static ISceneManager *sSceneManager = 0;
static ISceneNode *sLampskutta = 0;


bool LampskuttaFx::init()
{
    if (!gIrrDevice || !gIrrDevice->getSceneManager())
        return false;

    //bool zipRes = gIrrDevice->getFileSystem()->addFileArchive("data_oldies_hallintaa.zip", false, false, io::EFAT_ZIP);
    //assert(zipRes);

    sSceneManager = gIrrDevice->getSceneManager()->createNewSceneManager();

    ISceneManager *sceneManager = sSceneManager;

    sceneManager->loadScene("data/oldies/lampskutta.irr");

    //ISceneNode *light = sceneManager->getSceneNodeFromType(scene::ESNT_LIGHT);

    sLampskutta = sceneManager->getSceneNodeFromName("ruttu");

    sceneManager->addCameraSceneNode();
    vector3df cameraPosition(2, 2, 2);
    sceneManager->getActiveCamera()->setPosition(cameraPosition);
	sceneManager->getActiveCamera()->setTarget(sLampskutta->getPosition());
	
	mInitialized = true;
    return true;
}


void LampskuttaFx::render(double time, int timeMs)
{   
	vector3df eulerAngles((float)gTimeMs / 40.0f, (float)gTimeMs / 20.0f, (float)gTimeMs / 30.0f);
	sLampskutta->setRotation(eulerAngles);
	sSceneManager->drawAll();
}


void LampskuttaFx::deinit()
{
    sSceneManager->drop();
    mInitialized = false;
}
